//
//  EndBudgetViewController.swift
//  HuaYun
//
//  Created by Mac on 2019/3/25.
//  Copyright © 2019 xyxorigation. All rights reserved.
//

import UIKit

class EndBudgetViewController: BidDetailViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.load(with: "detail")
        // Do any additional setup after loading the view.
    }
    
    override func approvalAction(button: UIButton) {
        let approval = ApprovalSuggestionViewController()
        
        approval.ifpost = false
        
        approval.applyId = self.id
        
        approval.netPath = BidApprovalAction
        
        approval.businessType = "150"
        
        self.navigationController?.present(vc: approval)
    }
    
    override func configViewControllers() -> [UIViewController] {
        return [PurchaseTableViewController(),ApprovalRecordListViewController()]
    }
    
    
    override func param(for name: String) -> Dictionary<String, Any> {
        return ["id": self.id,"businessType": 150]
    }
    
    override func path(for name: String) -> String {
        return "projectManage/mobile/sys/settleProject/view"
    }

    override func success(for name: String) -> NetSuccess {
        func suc(json: JSON){
            var contents: [Dictionary<String,String?>] = []
            contents.append(["申请人:": json["data"]["applyUser"].string])
            let timestamp = json["data"]["createTime"].double ?? 0.0
            let date = Date.init(timeIntervalSince1970: TimeInterval.init(timestamp))
            contents.append(["申请时间:": date.dateLineStr])
            contents.append(["申请部门:": json["data"]["applyDept"].string])
            contents.append(["申请项目名称:": json["data"]["applyProjName"].string])
            contents.append(["结算项目名称:": json["data"]["resultProjName"].string])
            contents.append(["申请项目编号:": json["data"]["applyProjNum"].string])
            contents.append(["结算项目编号:": json["data"]["resultProjNum"].string])
            contents.append(["申请项目类型:": json["data"]["applyProjTypeName"].string])
            contents.append(["结算项目类型:": json["data"]["resultProjTypeName"].string])
            contents.append(["申请项目经理:": json["data"]["applyProjManager"].string])
            contents.append(["结算项目经理:": json["data"]["resultProjManager"].string])
            contents.append(["方向:": json["data"]["typesName"].string])
            let money = (json["data"]["projMoney"].double ?? 0.0) / 100.0
            contents.append(["金额(元):": String.init(format: "%.2f", money)])
            contents.append(["结算事由:": json["data"]["reason"].string])
            let attachments = json["data"]["attachFiles"].array ?? []
            let purchase = self.ctls[0] as! PurchaseTableViewController
            purchase.source = contents
            purchase.documents = attachments
            purchase.tableView.reloadData()
            let list = self.ctls[1] as! ApprovalRecordListViewController
            list.source = json["data"]["approvalProcessList"].array ?? []
            list.tableView.reloadData()
        }
        return suc
    }
    
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
